// AdaBoost.h: interface for the CAdaBoost class.
//
//////////////////////////////////////////////////////////////////////

#ifndef ADA_BOOST_H
#define ADA_BOOST_H

#include <math.h>
#include "ASample.h"

////////////////////////////////////////////////////
////////////////////////////////////////////////////
// weak learner
class CWeakLearner
{
public:
	CWeakLearner(){}
	CWeakLearner(int fn, double e)
	{
		fea_no = fn;
		er = e;
		beta = er / (1 - er);
		if (beta > 0.00000001) 
			alpha = log(1 / beta);
		else
			alpha = 100000;
	}
	CWeakLearner operator=(const CWeakLearner& wl)
	{
		fea_no = wl.fea_no;
		er = wl.er;
		beta = wl.beta;
		alpha = wl.alpha;
		return *this;
	}
	int fea_no;  // No. of weak learner
	double er;   // Error rate
	double beta; // calculated from er
	double alpha;// calculated from er
};


////////////////////////////////////////////////////
////////////////////////////////////////////////////
// adaboost classifier
class CAdaBoost  
{
public:
	void	GetClassifiers(vfloat &vfAlpha, vint &vnClassifiers);
	CAdaBoost(int T);
	virtual ~CAdaBoost();

	int		Classify(const char *strFileName);
	void	Verify();
	void	UpdateWeights(CWeakLearner &wl);
	void	LoadBinH(const char * strFileName);
	void	NormWeights();
	int		Boost(double fPosW);
	void	WriteClassifier(const char * strFileName, const char * strFiltersPath);
	CWeakLearner MinErrorWeakLearner();

protected:
	int		m_T;  // number of features to be selected
	int		m_nPos;
	int		m_nNeg;
	int		m_nFilters;
	double	m_SumAlpha;
	uchar *	m_pbH;
	std::vector<CWeakLearner> m_vWeakLearner;
	std::vector<double> m_vWeights;
};


#endif
